<template>
  <el-upload
  class="avatar-uploader"
  :action="URL.PIC+'api/qiNiuContent'"
  :show-file-list="false"
    name="file"
    :on-success="handleSuccess"
    :on-error="handleError"
    :on-progress="handleProgress"
    :before-upload="beforeUpload">
    <el-button size="small" type="primary">点击上传</el-button>
    <img v-if="img" :src="URL.PIC+img" class="avatar maxs">
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload>
</template>

<script>

export default {
  props: ['img'],
  data() {
    return {

    }
  },
  created() {

  },
  methods: {
    // 上传之前
    beforeUpload(file, fileList) {
      const isLt1M = file.size / 1024 / 1024 < 1;
      if (!isLt1M) {
        this.$message.error('上传的图片大小不能超过 1MB!');
        return false;
      }
    },
    // 上传成功
    handleSuccess(file) {
      this.$emit('getUploadImg', file)
    },
    // 上传失败
    handleError(file) {
      this.actionsAfter('上传失败，请稍后再试！', 'error')
    },
    handleProgress() {

    }
  }
}
</script>

<style lang="scss">
.avatar-uploader{
  .el-upload{
    text-align: left !important;
    vertical-align: top;
  }
  .avatar{
    margin-left: 50px;
    vertical-align: bottom;
  }
}

</style>
